<?php

namespace App\Repositories;

use Prettus\Repository\Contracts\RepositoryInterface;

/**
 * Interface BaseRepository.
 *
 * @package namespace App\Repositories;
 */
interface BaseRepository extends RepositoryInterface
{
    //
    /**
     * 重写 find 方法
     * 获取model 对象 如果没有数据 则返回 空的model对象 而不是null
     * @param $id
     * @param array $columns
     * User: Zhangxy
     * Date: 2018-08-13
     * @return mixed connection or model
     */
    public function find($id, $columns = ['*']);

    /**
     * 用主键获取一个model 对象 如果查找不到则抛出异常
     * 因为重写了 repository 库的 find 方法 这里补齐
     * @param $id
     * @param array $columns
     * User: Zhangxy
     * Date: 2018-09-05
     * @return mixed
     */
    public function findOrFail($id, $columns = ['*']);

    /**
     * 使用数组 填充 where 条件
     * 参考 BaseRepository applyConditions
     * $conditions = [
     * 'a'=>1,
     * 'b'=>['b','>',2],
     * 'c'=>['c','<',3],
     * 'd'=>['d','whereIn',[1,2,3]],
     * 'e'=>['e','whereNUll'],
     * ];
     * @param array $where
     * User: Zhangxy
     * Date: 2018-08-27
     * @return $this
     */
    public function addConditions(array $where);

    /**
     * 根据where条件更新数据
     * 一定要注意 where条件 可能会影响多行
     * @param array $attributes
     * @param array $where
     * User: Zhangxy
     * Date: 2018-08-27
     * @return bool|int
     */
    public function updateByWhere(array $attributes, array $where);

    /**
     * skip
     * @param int $value
     * User: Zhangxy
     * Date: 2018-09-19
     * @return $this
     */
    public function skip($value = 0);

    /**
     * take
     * @param int $limit
     * User: Zhangxy
     * Date: 2018-09-19
     * @return $this
     */
    public function take($limit = 0);

    /**
     * offset
     * @param int $value
     * User: Zhangxy
     * Date: 2018-09-19
     * @return $this
     */
    public function offset($value = 0);

    /**
     * limit
     * @param int $limit
     * User: Zhangxy
     * Date: 2018-09-19
     * @return $this
     */
    public function limit($limit = 0);

    /**
     * count
     * User: Zhangxy
     * Date: 2018-08-28
     * @return mixed
     */
    public function count();

    /**
     * max
     * @param $field
     * User: Zhangxy
     * Date: 2018-09-06
     * @return mixed
     */
    public function max($field);

    /**
     * min
     * @param $field
     * User: Zhangxy
     * Date: 2018-09-06
     * @return mixed
     */
    public function min($field);

    /**
     * avg
     * @param $field
     * User: Zhangxy
     * Date: 2018-09-06
     * @return mixed
     */
    public function avg($field);

    /**
     * sum
     * @param $field
     * User: Zhangxy
     * Date: 2018-09-06
     * @return mixed
     */
    public function sum($field);

    /**
     * 将已经删除的也提取出来
     * User: Zhangxy
     * Date: 2018-08-27
     * @return $this
     */
    public function withTrashed();

    /**
     * 可排序字段
     * User: Zhangxy
     * Date: 2018-08-15
     * @return array
     */
    public function getFieldSortable();

    /**
     * api使用的分页方法
     * @param null $limit
     * @param array $columns
     * @param string $method
     * User: Zhangxy
     * Date: 2018-08-30
     * @return mixed
     */
    public function apiPaginate($limit = null, $columns = ['*'], $method = "paginate");
}
